/*
 * Copyright 2011 Alex Paréj.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.mkdir.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.codec.digest.DigestUtils;
import org.mkdir.util.Konstans;

/**
 *
 * @author Alex Paréj
 */
@Entity
@Table(name = "FELHASZNALOK")
@NamedQueries({
    @NamedQuery(name = "Felhasznalo.findAll", query = "SELECT f FROM Felhasznalo f")})
public class Felhasznalo extends AbstractEntitiy<Integer> implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "FELHASZNALO_ID")
    private Integer id;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LETREHOZO")
    private Felhasznalo felhasznalo;
    @Basic(optional = false)
    @NotNull
    @Size(max = 254)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Size(max = 255)
    @Column(name = "NEV")
    private String nev;
    @Basic(optional = false)
    @NotNull
    @Size(max = 64)
    @Column(name = "JELSZO")
    private String jelszo;
    @Size(max = 50)
    @Column(name = "TELEFONSZAM")
    private String telefonszam;
    @Basic(optional = false)
    @NotNull
    @Column(name = "LETREHOZVA")
    @Temporal(TemporalType.DATE)
    private Date letrehozva;
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "PROFIL_KEP")
    private byte[] profilKep;
    @Basic(optional = false)
    @NotNull
    @Column(name = "LOMTAR")
    private Character lomtarHasznalata;
    @Basic(optional = false)
    @NotNull
    @Column(name = "TARHELY")
    //MB-ban
    private Integer tarhely;
    @Basic(optional = false)
    @NotNull
    @Column(name = "STILUS")
    private String stilus;
    @Basic(optional = false)
    @NotNull
    @Column(name = "EMAIL_ERTESITES")
    private Character emailErtesites;
    @Basic(optional = false)
    @NotNull
    @Column(name = "INFO_ABLAK_HOSSZ")
    private Integer infoAblakMegjlHossza;

    public Felhasznalo() {
    }

    public Felhasznalo(Integer feId) {
        this.id = feId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Felhasznalo getFelhasznalo() {
        return felhasznalo;
    }

    public void setFelhasznalo(Felhasznalo felhasznalo) {
        this.felhasznalo = felhasznalo;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public void setJelszo(String jelszo) {
        this.jelszo = DigestUtils.sha256Hex(jelszo);
    }

    public Date getLetrehozva() {
        return letrehozva;
    }

    public void setLetrehozva(Date letrehozva) {
        this.letrehozva = letrehozva;
    }

    public String getNev() {
        return nev;
    }

    public void setNev(String nev) {
        this.nev = nev;
    }

    public byte[] getProfilKep() {
        return profilKep;
    }

    public void setProfilKep(byte[] profilKep) {
        this.profilKep = profilKep;
    }

    public String getTelefonszam() {
        return telefonszam;
    }

    public void setTelefonszam(String telefonszam) {
        this.telefonszam = telefonszam;
    }

    public void setLomtarHasznalata(boolean hasznal) {
        if (hasznal) {
            this.lomtarHasznalata = Konstans.IGEN;
        } else {
            this.lomtarHasznalata = Konstans.NEM;
        }
    }

    public boolean isLomtarHasznalata() {
        if (lomtarHasznalata != null && lomtarHasznalata.equals(Konstans.IGEN)) {
            return true;
        }
        return false;
    }

    public Integer getTarhely() {
        return tarhely;
    }

    public void setTarhely(Integer tarhely) {
        this.tarhely = tarhely;
    }

    public String getStilus() {
        return stilus;
    }

    public void setStilus(String stilus) {
        this.stilus = stilus;
    }

    public boolean isEmailErtesites() {
        if (emailErtesites != null && emailErtesites.equals(Konstans.IGEN)) {
            return true;
        }
        return false;
    }

    public void setEmailErtesites(boolean emailErtesites) {
        if (emailErtesites) {
            this.emailErtesites = Konstans.IGEN;
        } else {
            this.emailErtesites = Konstans.NEM;
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public Integer getInfoAblakMegjlHossza() {
        return infoAblakMegjlHossza;
    }

    public void setInfoAblakMegjlHossza(Integer infoAblakMegjlHossza) {
        this.infoAblakMegjlHossza = infoAblakMegjlHossza;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Felhasznalo)) {
            return false;
        }
        Felhasznalo other = (Felhasznalo) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.mkdir.model.Felhasznalo[ feId=" + id + " ]";
    }
}
